package main

import "strings"

func wordPattern(pattern string, s string) bool {
	ss := strings.Split(s, " ")
	if len(pattern) != len(ss) {
		return false
	}
	m := map[byte]string{}
	m2 := map[string]byte{}
	for i, sub := range ss {
		p := pattern[i]
		exists, ok := m[p]
		if ok {
			if exists != sub {
				return false
			}
		} else {
			m[p] = sub
		}

		p2, ok2 := m2[sub]
		if ok2 {
			if p2 != p {
				return false
			}
		} else {
			m2[sub] = p
		}
	}
	return true
}

func main() {
	res := wordPattern("abba", "dog dog dog dog")
	println(res)
}
